﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankSystem
{
    internal static class AccountBase // 账户数据库
    {
        public static int numOfAccounts = 10;
        public static string[] ids;
        public static Account[] accounts;
        static AccountBase()
        {
            // 先初始化，才能赋值
            ids = new string[10];
            accounts = new Account[10];
            // 随机生成卡号
            Random random = new Random();
            HashSet<int> uniqueRandomNumbers = new HashSet<int>();
            while (uniqueRandomNumbers.Count < numOfAccounts) // 生成互不相同的若干个账号
            {
                int randomNumber = random.Next(1, 1000000000);
                if (!uniqueRandomNumbers.Contains(randomNumber))
                {
                    uniqueRandomNumbers.Add(randomNumber);
                }
            }
            int cnt = 0;
            foreach (int number in uniqueRandomNumbers)
            {
                ids[cnt] = number.ToString();
                cnt++;
            }
            // 生成账户类型、存款和限额。
            for (int i = 0; i < 10; i++)
            {
                int type = random.Next(0, 2);// 类型
                int balance = random.Next(0, 100000);// 存款
                // 0：储蓄账户，1：信用账户
                if(type == 0)
                {
                    accounts[i] = new SavingAccount(ids[i], type, balance);
                }
                else
                {
                    int lim = random.Next(1, 11);// 信用额度
                    accounts[i] = new CreditAccount(ids[i], type, balance, lim * 1000);
                }
            }
        }
    }
}
